package util;

import java.util.Queue;
import java.util.Stack;

/**
 * QueueReverser is a class that simply is used for 
 * reversing objects of Queue type. A QueueReverser
 * object takes a Queue and can then reverse it by
 * calling a method.
 * 
 * @author Tobias
 *
 */
public class QueueReverser {
	/**
	 * Reverses the queue last set by the constructor or the 
	 * setQueue() method.
	 */
	public static <E> void reverseQueue(Queue<E> queue){
		Stack<E> tmpStack = new Stack<E>();
		
		for(int i = 0; i < queue.size(); i++){
			tmpStack.add(queue.poll());
		}
		queue.addAll(tmpStack);
	}
}
